<?php

namespace common\models\datas;

use common\components\behaviors\UpdateCacheBehavior;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%setting}}".
 *
 * @property integer $id
 * @property string $item
 * @property string $value
 * @property integer $branch_id
 * @property integer $user_id
 * @property integer $created_at
 */
class Setting extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%setting}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['branch_id', 'user_id', 'created_at', 'updated_at'], 'integer'],
            [['item', 'key'], 'string', 'max' => 100],
            [['value'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'ID'),
            'item' => Yii::t('common', '配置项'),
            'value' => Yii::t('common', '配置值'),
            'branch_id' => Yii::t('common', '分店id'),
            'user_id' => Yii::t('common', '创建用户'),
            'created_at' => Yii::t('common', '创建时间'),
            'updated_at' => Yii::t('common', '更新时间'),
            'key' => Yii::t('common', '名称'),
        ];
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
            [
                'class' => UpdateCacheBehavior::className(),
                'cacheName' => 'setting'
            ]

        ]);
    }
}
